package com.infitecs.eyas.session;

import com.infitecs.eyas.blower.dao.BlowerBaseCalDao;
import com.infitecs.eyas.blower.dao.BlowerDesDao;
import com.infitecs.eyas.blower.model.BlowerBaseCal;
import com.infitecs.eyas.blower.model.BlowerDes;
import com.infitecs.eyas.combustion.dao.*;
import com.infitecs.eyas.combustion.model.*;
import com.infitecs.eyas.constant.Constant;
import com.infitecs.eyas.mill.dao.MillSelectCalculateDao;
import com.infitecs.eyas.mill.dao.MillSelectDao;
import com.infitecs.eyas.mill.dao.PipeCalculateDao;
import com.infitecs.eyas.mill.dao.SystemHeatDao;
import com.infitecs.eyas.mill.model.MillSelect;
import com.infitecs.eyas.mill.model.MillSelectCalculate;
import com.infitecs.eyas.mill.model.PipeCalculate;
import com.infitecs.eyas.mill.model.SystemHeat;
import com.infitecs.eyas.nature.dao.NatureDao;
import com.infitecs.eyas.nature.model.Nature;
import com.infitecs.eyas.oncefan.dao.OnceFanBaseCalDao;
import com.infitecs.eyas.oncefan.dao.OnceFanDesDao;
import com.infitecs.eyas.oncefan.model.OnceFanBaseCal;
import com.infitecs.eyas.oncefan.model.OnceFanDes;
import com.infitecs.eyas.power.model.Power;
import com.infitecs.eyas.power.service.PowerService;
import com.infitecs.eyas.quality.dao.AshDao;
import com.infitecs.eyas.quality.dao.BurstDao;
import com.infitecs.eyas.quality.dao.ElementDao;
import com.infitecs.eyas.quality.dao.IndustryDao;
import com.infitecs.eyas.quality.model.Ash;
import com.infitecs.eyas.quality.model.Burst;
import com.infitecs.eyas.quality.model.Element;
import com.infitecs.eyas.quality.model.Industry;
import com.infitecs.eyas.result.dao.MiddleResultDao;
import com.infitecs.eyas.session.model.Param;
import com.infitecs.eyas.step.dao.StepDao;
import com.infitecs.eyas.step.modal.StepInfo;
import com.infitecs.eyas.suction.dao.SuctionCalcaulatorBaseDao;
import com.infitecs.eyas.suction.dao.SuctionDesDao;
import com.infitecs.eyas.suction.model.SuctionDes;
import com.infitecs.eyas.suction.model.SunctionCalcalatorBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;

//import com.infitecs.eyas.tool.Transition;

/**
 *
 */
@Service
public class SessionService {
    private char environment;

    private HashMap<String, Double> paramMap;


    @Autowired
    private SuctionCalcaulatorBaseDao suctionCalcaulatorBaseDao;

    @Autowired
    private PowerService powerService;

    @Autowired
    private ElementDao elementDao;

    @Autowired
    private HttpSession session;

    @Autowired
    private IndustryDao industryDao;

    @Autowired
    private AshDao ashDao;

    @Autowired
    private BurstDao burstDao;

    @Autowired
    private NatureDao natureDao;

    @Autowired
    private SuctionDesDao suctionDesDao;

    @Autowired
    private BurnDao burnDao;

    @Autowired
    private PollutantDao pollutantDao;

    @Autowired
    private CleanDao cleanDao;

    @Autowired
    private DewPointDao dewPointDao;

    @Autowired
    private ChimneyDao chimneyDao;

    @Autowired
    private StepDao stepDao;

    @Autowired
    private MillSelectDao millSelectDao;

    @Autowired
    private MillSelectCalculateDao millSelectCalculateDao;

    @Autowired
    private SystemHeatDao systemHeatDao;

    @Autowired
    private PipeCalculateDao pipeCalculateDao;

    @Autowired
    private OnceFanDesDao onceFanDesDao;

    @Autowired
    private BlowerDesDao blowerDesDao;

    @Autowired
    private OnceFanBaseCalDao onceFanBaseCalDao;

    @Autowired
    private BlowerBaseCalDao blowerBaseCalDao;

    public void setEnvironment(char E) {
        environment = E;
    }

    public char getE() {
        return environment;
    }

    public int getCaseId() {
        return Integer.parseInt(session.getAttribute("caseId").toString());
    }

    public int getPowerId() {
        return Integer.parseInt(session.getAttribute("powerId").toString());
    }

    public void setPowerIdAndCaseId(Power power) {
        setPowerIdAndCaseId(power.getPowerCaseId() + "");
    }

    public void setPowerIdAndCaseId(String caseId) {
        HashMap<Integer, Integer> stepState = new HashMap<>();
        session.setAttribute("caseId", caseId);
        session.setAttribute("powerId", String.valueOf(powerService.getPowerByCaseId(Integer.parseInt(caseId))));
        addParamMap(caseId);
        List<StepInfo> stepInfoList = stepDao.getStepListByCaseId(caseId);
        for (StepInfo stepInfo : stepInfoList) {
            stepState.put(stepInfo.getStepId(), stepInfo.getState());
        }
        session.setAttribute("stepState", stepState);
    }

    public void addPowerMap() {
        HashMap<Integer, HashMap<String, Double>> powerMap = new HashMap<>();
        if (null == session.getAttribute("powerMap"))
            session.setAttribute("powerMap", powerMap);
    }

    public HashMap<Integer, HashMap<String, Double>> getPowerMap() {
        return (HashMap<Integer, HashMap<String, Double>>) session.getAttribute("powerMap");
    }

    public void addParamMap(String caseId) {
        paramMap = new HashMap<>();
        paramMap.put("EPI314", Math.PI);
        HashMap powerMap = getPowerMap();
        if (powerMap != null)
            getPowerMap().put(Integer.parseInt(caseId), paramMap);
    }

    public HashMap<String, Double> getParamMap() {
        return paramMap;
    }

    public void putParamMap(Object object) {
        if (object == null)
            return;
        Param param = (Param) object;
        String paramName = param.getParamName();
        Double paramValue = param.getParamValue();
        if (null != paramValue && paramMap != null)
            paramMap.put(paramName, paramValue);
    }

    public int putIndustryValue(int caseId) {
        Industry industry = industryDao.getIndustryByPowerCaseId(caseId);
        if (null != industry && null != paramMap) {
            paramMap.put("ME3", industry.getMar());
            paramMap.put("ME4", industry.getMad());
            paramMap.put("ME5", industry.getMf());
            paramMap.put("ME6", industry.getAar());
            paramMap.put("ME9", industry.getVar());
            paramMap.put("ME10", industry.getVdaf());
        }
        return 6;
    }

    public int putElementValue(int caseId) {
        int count = putIndustryValue(caseId);
        Element element = elementDao.getElementByPowerCaseId(caseId);
        if (null != element) {
            //ME13=ME15
            paramMap.put("ME13", element.getQnetAr());
            paramMap.put("ME14", element.getQnetArOther());
            paramMap.put("ME15", element.getQnetAr());
            paramMap.put("ME18", element.getQnetArOther());
            //ME17=ME19
            paramMap.put("ME17", element.getQgrAr());
            paramMap.put("ME19", element.getQgrAr());
            paramMap.put("ME26", element.getCar());
            paramMap.put("ME27", element.getHar());
            paramMap.put("ME28", element.getOar());
            paramMap.put("ME29", element.getNar());
            paramMap.put("ME30", element.getSar());
            paramMap.put("ME31", element.getSum());
        }
        return 12 + count;
    }

    public int putAshValue(int caseId) {
        int count = putElementValue(caseId);
        Ash ash = ashDao.getAshByPowerCaseId(caseId);
        if (null != paramMap) {
            if (null != ash) {
                paramMap.put("ME33", ash.getSio2());
                paramMap.put("ME34", ash.getAl2o3());
                paramMap.put("ME35", ash.getFe2o3());
                paramMap.put("ME36", ash.getCao());
                paramMap.put("ME37", ash.getTio2());
                paramMap.put("ME38", ash.getMgo());
                paramMap.put("ME39", ash.getSo3());
                paramMap.put("ME40", ash.getK2o());
                paramMap.put("ME41", ash.getNa2o());
                paramMap.put("ME48", ash.getOther());
                paramMap.put("ME49", ash.getTotal());
                paramMap.put("ME53", ash.getDt());
                paramMap.put("ME54", ash.getSt());
                paramMap.put("ME55", ash.getHt());
                paramMap.put("ME56", ash.getFt());
                paramMap.put("ME57", ash.getRt());
            }
        }
        return 16 + count;
    }
    public int putBurstValue(int caseId) {
        int count = putAshValue(caseId);
        Burst burst = burstDao.getBurstByPowerCaseId(caseId);
        if (null != paramMap) {
            if (null != burst) {
                paramMap.put("ME21", burst.getHgi());
                paramMap.put("ME22", burst.getKvti());
                paramMap.put("ME23", burst.getKe());
                paramMap.put("ME24", burst.getAi());
                paramMap.put("ME50", burst.getKgc());
                paramMap.put("ME51", burst.getHm());
                paramMap.put("ME80", burst.getKd());
            }
        }
        return 7 + count;
    }

    public int putNatureValue(int powerId) {
        Nature nature = natureDao.getNatureByPowerId(powerId);
        if (null != paramMap) {
            if (null != nature) {
                paramMap.put("ZE3", nature.getAltitude());
                paramMap.put("ZE4", nature.getLocalPressure());
                paramMap.put("ZE5", nature.getLocalPressureOther());
                paramMap.put("ZE6", 101.325);
                paramMap.put("ZE7", 760.0);
                paramMap.put("ZE8", 1.285);
                paramMap.put("ZE9", 0.804);
                paramMap.put("ZE10", nature.getAnnualAverageTemperature());
                paramMap.put("ZE11", nature.getOutdoorCalculatedTemperature());
                paramMap.put("ZE12", nature.getMinDailyAverageTemperature());
                paramMap.put("ZE13", nature.getAnnualAverageRelativeHumidity());
                paramMap.put("ZE14", nature.getAnnualAverageAirMoisture());
                paramMap.put("ZE15", nature.getLocalDensityMoistAir());
                paramMap.put("ZE16", nature.getSummerOutdoorCalculateTemperature());
            }
        }
        return 10;
    }

    public int putBurnValue(int caseId) {
        putBurstValue(caseId);
        putNatureValue(getPowerId());
        CalculateBurn calculateBurn = burnDao.getCalculateBurnByCaseId(caseId);
        if (null != paramMap && null != calculateBurn) {
            //�� 19 ��
            paramMap.put("RE3", calculateBurn.getE3());
            paramMap.put("RE191", 1.0);
            paramMap.put("RE4", calculateBurn.getE4());
            paramMap.put("RE6", calculateBurn.getE6());
            paramMap.put("RE8", calculateBurn.getE8());
            paramMap.put("RE20", calculateBurn.getE20());
            paramMap.put("RE54", calculateBurn.getE54());
            paramMap.put("RE55", calculateBurn.getE55());
            paramMap.put("RE56", calculateBurn.getE56());
            paramMap.put("RE70", calculateBurn.getE70());
            paramMap.put("RE88", calculateBurn.getE88());
            paramMap.put("RE89", calculateBurn.getE89());
            paramMap.put("RE103", calculateBurn.getE103());
            paramMap.put("RE122", calculateBurn.getE122());
            paramMap.put("RE123", calculateBurn.getE123());
            paramMap.put("RE137", calculateBurn.getE137());
            paramMap.put("RE155", calculateBurn.getE155());
            paramMap.put("RE156", calculateBurn.getE156());
            paramMap.put("RE170", calculateBurn.getE170());
            paramMap.put("RE171", calculateBurn.getE171());
        }
        return 19;
    }

    public int putPollutantValue(int caseId) {
        putBurnValue(caseId);
        CalculatePollution calculatePollution = pollutantDao.getCalculatePollution(caseId);
        if (null != paramMap && calculatePollution != null) {
            paramMap.put("RE184", calculatePollution.getE184());
            paramMap.put("RE185", calculatePollution.getE185());
            paramMap.put("RE187", calculatePollution.getE187());
            paramMap.put("RE188", calculatePollution.getE188());
            paramMap.put("RE189", calculatePollution.getE189());
            paramMap.put("RE191", 1.0);
            paramMap.put("RE192", calculatePollution.getE192());
            paramMap.put("RE193", calculatePollution.getE193());
            paramMap.put("RE205", calculatePollution.getE205());
            paramMap.put("RE206", calculatePollution.getE206());
            paramMap.put("RE207", calculatePollution.getE207());
            paramMap.put("RE208", calculatePollution.getE208());
            paramMap.put("RE210", calculatePollution.getE210());
            paramMap.put("RE211", calculatePollution.getE211());
            paramMap.put("RE212", calculatePollution.getE212());
            paramMap.put("RE216", calculatePollution.getE216());
            paramMap.put("RE218", calculatePollution.getE218());
            paramMap.put("RE330", calculatePollution.getE330());
        }
        return 17;
    }


    public int putCleanValue(int caseId) {
        putPollutantValue(caseId);
        CalculateClean calculateClean = cleanDao.getCalculateClean(caseId);
        if (null != paramMap && calculateClean != null) {
            //�� 24 ��
            paramMap.put("RE221", calculateClean.getE221());
            paramMap.put("RE222", calculateClean.getE222());
            paramMap.put("RE223", calculateClean.getE223());
            paramMap.put("RE224", calculateClean.getE224());
            paramMap.put("RE227", calculateClean.getE227());
            paramMap.put("RE228", calculateClean.getE228());
            paramMap.put("RE229", calculateClean.getE229());
            paramMap.put("RE230", calculateClean.getE230());
            paramMap.put("RE231", calculateClean.getE231());
            paramMap.put("RE241", calculateClean.getE241());
            paramMap.put("RE242", calculateClean.getE242());
            paramMap.put("RE244", calculateClean.getE244());
            paramMap.put("RE246", calculateClean.getE246());
            paramMap.put("RE248", calculateClean.getE248());
            paramMap.put("RE253", calculateClean.getE253());
            paramMap.put("RE254", calculateClean.getE254());
            paramMap.put("RE255", calculateClean.getE255());
            paramMap.put("RE257", calculateClean.getE257());
            paramMap.put("RE258", calculateClean.getE258());
            paramMap.put("RE262", calculateClean.getE262());
            paramMap.put("RE263", calculateClean.getE263());
            paramMap.put("RE264", calculateClean.getE264());
            paramMap.put("RE285", calculateClean.getE285());
            paramMap.put("RE331", calculateClean.getE331());
        }
        return 24;
    }

    public int putDewPointValue(int caseId) {
        putCleanValue(caseId);
        CalculateDewPoint calculateDewPoint = dewPointDao.getCalculateDewPoint(caseId);
        CalculateBurn calculateBurn = burnDao.getCalculateBurnByCaseId(caseId);
        if (calculateBurn != null) {
            paramMap.put("RE55", calculateBurn.getE55());
        }
        if (null != paramMap && calculateDewPoint != null) {
            paramMap.put("RE221", calculateDewPoint.getE291());
            paramMap.put("RE222", calculateDewPoint.getE292());
            paramMap.put("RE223", calculateDewPoint.getE293());
            paramMap.put("RE224", calculateDewPoint.getE294());
            paramMap.put("RE227", calculateDewPoint.getE295());
            paramMap.put("RE228", calculateDewPoint.getE296());
            paramMap.put("RE229", calculateDewPoint.getE298());
            paramMap.put("RE230", calculateDewPoint.getE299());
            paramMap.put("RE231", calculateDewPoint.getE300());
            paramMap.put("RE241", calculateDewPoint.getE301());
            paramMap.put("RE242", calculateDewPoint.getE303());
        }
        return 11;
    }

    public int putChimneyValue(int caseId) {
        putDewPointValue(caseId);
        CalculateChimney calculateChimney = chimneyDao.getCalculateChimney(caseId);
        if (null != paramMap && calculateChimney != null) {
            //�� 17 ��
            paramMap.put("RE306", calculateChimney.getE306());
            paramMap.put("RE307", calculateChimney.getE307());
            paramMap.put("RE308", calculateChimney.getE308());
            paramMap.put("RE309", calculateChimney.getE309());
            paramMap.put("RE314", calculateChimney.getE314());
            paramMap.put("RE315", calculateChimney.getE315());
            paramMap.put("RE316", calculateChimney.getE316());
            paramMap.put("RE318", calculateChimney.getE318());
            paramMap.put("RE320", calculateChimney.getE320());
            paramMap.put("RE321", calculateChimney.getE321());
            paramMap.put("RE322", calculateChimney.getE322());
            paramMap.put("RE323", calculateChimney.getE323());
            paramMap.put("RE324", calculateChimney.getE324());
            paramMap.put("RE325", calculateChimney.getE325());
            paramMap.put("RE326", calculateChimney.getE326());
            paramMap.put("RE327", calculateChimney.getE327());
            paramMap.put("RE328", calculateChimney.getE328());
        }
        return 17;
    }

    public int putMillSelectValue(int caseId) {
        int count = putChimneyValue(caseId);
        MillSelect millSelect = millSelectDao.getMillSelect(caseId);
        if (null != millSelect && null != paramMap) {
            paramMap.put("AE2", millSelect.getE2());
            paramMap.put("AE3", millSelect.getE3());
            paramMap.put("AE4", millSelect.getE4());
            paramMap.put("AE5", millSelect.getE5());
            paramMap.put("AE6", millSelect.getE6());
            paramMap.put("AE7", millSelect.getE7());
            paramMap.put("AE8", millSelect.getE8());
            paramMap.put("AE9", millSelect.getE9());
            paramMap.put("AE12", millSelect.getE12());
            paramMap.put("AE54", millSelect.getE54());
            paramMap.put("AE61", millSelect.getE61());
            paramMap.put("AE67", millSelect.getE67());
            paramMap.put("AE74", millSelect.getE74());
            paramMap.put("AE75", millSelect.getE75());
            paramMap.put("AE87", millSelect.getE87());
        }
        return 15 + count;
    }

    public int putSelectCalculateValue(int caseId) {
        int count = putMillSelectValue(caseId);
        MillSelectCalculate millSelectCalculate = millSelectCalculateDao.getSelectCalculate(caseId);
        if (null != millSelectCalculate && null != paramMap) {
            paramMap.put("AE10", millSelectCalculate.getE10());
            paramMap.put("AE13", millSelectCalculate.getE13());
            paramMap.put("AE14", millSelectCalculate.getE13());
            paramMap.put("AE15", millSelectCalculate.getE13());
            paramMap.put("AE16", millSelectCalculate.getE13());
            paramMap.put("AE17", millSelectCalculate.getE17());
            paramMap.put("AE18", millSelectCalculate.getE17());
            paramMap.put("AE19", millSelectCalculate.getE17());
            paramMap.put("AE20", millSelectCalculate.getE17());
            paramMap.put("AE21", millSelectCalculate.getE21());
            paramMap.put("AE22", millSelectCalculate.getE21());
            paramMap.put("AE23", millSelectCalculate.getE21());
            paramMap.put("AE24", millSelectCalculate.getE21());
            paramMap.put("AE32", millSelectCalculate.getE32());
            paramMap.put("AE33", millSelectCalculate.getE33());
            paramMap.put("AE34", millSelectCalculate.getE34());
            paramMap.put("AE35", millSelectCalculate.getE35());
            paramMap.put("AE36", millSelectCalculate.getE36());
            paramMap.put("AE37", millSelectCalculate.getE37());
            paramMap.put("AE38", millSelectCalculate.getE38());
            paramMap.put("AE39", millSelectCalculate.getE39());
            paramMap.put("AE40", millSelectCalculate.getE40());
            paramMap.put("AE42", millSelectCalculate.getE42());
            paramMap.put("AE43", millSelectCalculate.getE43());
            paramMap.put("AE44", millSelectCalculate.getE44());
            paramMap.put("AE45", millSelectCalculate.getE45());
            paramMap.put("AE46", millSelectCalculate.getE46());
            paramMap.put("AE47", millSelectCalculate.getE47());
        }
        return 19 + count;
    }

    public int putSystemHeatValue(int caseId) {
        int count = putSelectCalculateValue(caseId);
        SystemHeat systemHeat = systemHeatDao.getSystemHeat(caseId);
        if (null != paramMap && null != systemHeat) {
            paramMap.put("AE50", systemHeat.getE50());
            paramMap.put("AE52", systemHeat.getE52());
            paramMap.put("AE53", systemHeat.getE53());
            paramMap.put("AE55", systemHeat.getE55());
            paramMap.put("AE56", systemHeat.getE56());
            paramMap.put("AE57", systemHeat.getE57());
            paramMap.put("AE59", systemHeat.getE59());
            paramMap.put("AE65", systemHeat.getE65());
            paramMap.put("AE66", systemHeat.getE66());
            paramMap.put("AE70", systemHeat.getE70());
            paramMap.put("AE71", systemHeat.getE71());
            paramMap.put("AE77", systemHeat.getE77());
            paramMap.put("AE79", systemHeat.getE79());
            paramMap.put("AE82", systemHeat.getE82());
            paramMap.put("AE84", systemHeat.getE84());
            paramMap.put("AE86", systemHeat.getE86());
            paramMap.put("AE89", systemHeat.getE89());
            paramMap.put("AE90", systemHeat.getE90());
            paramMap.put("AE92", systemHeat.getE92());
            paramMap.put("AE95", systemHeat.getE95());
            paramMap.put("AE97", systemHeat.getE97());
            paramMap.put("AE100", systemHeat.getE100());
            paramMap.put("AE102", systemHeat.getE102());
            paramMap.put("AE103", systemHeat.getE103());
            paramMap.put("AE105", systemHeat.getE105());
            paramMap.put("AE106", systemHeat.getE106());
            paramMap.put("AE107", systemHeat.getE107());
            paramMap.put("AE108", systemHeat.getE108());
            paramMap.put("AE109", systemHeat.getE109());
            paramMap.put("AE110", systemHeat.getE110());
            paramMap.put("AE111", systemHeat.getE111());
        }
        return 31 + count;
    }

    public int putPipeCalculateValue(int caseId) {
        int count = putSystemHeatValue(caseId);
        PipeCalculate pipeCalculate = pipeCalculateDao.getPipeCalculate(caseId);
        if (null != paramMap && null != pipeCalculate) {
            paramMap.put("AE115", pipeCalculate.getE115());
            paramMap.put("AE116", pipeCalculate.getE116());
            paramMap.put("AE117", pipeCalculate.getE117());
            paramMap.put("AE118", pipeCalculate.getE118());
            paramMap.put("AE119", pipeCalculate.getE119());
            paramMap.put("AE120", pipeCalculate.getE120());
        }
        return 6 + count;
    }

    public int putSuctionDesInit(int caseId) {
        int count = putPipeCalculateValue(caseId);
        SuctionDes suctionDes = suctionDesDao.getOnceFandes(caseId);
        if (null != paramMap && null != suctionDes ) {
            paramMap.put("YE6",suctionDes.getE6());
            paramMap.put("YE9",suctionDes.getE9());
            paramMap.put("YE7", suctionDes.getE7());
            paramMap.put("YE8", suctionDes.getE8());
            paramMap.put("YE10", suctionDes.getE10());
            paramMap.put("YE1",suctionDes.getE1());
            paramMap.put("YE4", suctionDes.getE4());
            paramMap.put("YE2", suctionDes.getE2());
            paramMap.put("YE3", suctionDes.getE3());
            paramMap.put("YE5", suctionDes.getE5());
            paramMap.put("YE16", suctionDes.getE16());
            paramMap.put("YE17", suctionDes.getE17());
            paramMap.put("YE18", suctionDes.getE18());
            paramMap.put("YE40", suctionDes.getE40());
            paramMap.put("YE52", suctionDes.getE52());
            paramMap.put("YE66", suctionDes.getE66());
        }
        return count + 16;
    }

    public int putSuctionCalInit(int caseId) {
        return putSuctionDesInit(caseId);

    }

    public int putSuctionSummaryInit(int caseId) {
        int count = putSuctionCalInit(caseId);
        SunctionCalcalatorBase sunctionCalcalatorBase = suctionCalcaulatorBaseDao.getSuctionCalaulatorBaseByCaseId(caseId);
        if (sunctionCalcalatorBase != null) {
            paramMap.put("YE22",sunctionCalcalatorBase.getE22());
            paramMap.put("YE10",sunctionCalcalatorBase.getE10());
            paramMap.put("YE32", sunctionCalcalatorBase.getE32());
            paramMap.put("YE33",sunctionCalcalatorBase.getE33());
            paramMap.put("YE35",sunctionCalcalatorBase.getE35());
            paramMap.put("YE36",sunctionCalcalatorBase.getE36());
        }
        return count + 6;
    }

    public int putOnceFanDesInit(int caseId) {
        int count = putSuctionSummaryInit(caseId);
        OnceFanDes onceFanDes = onceFanDesDao.getOnceFanDes(caseId);
        if (null != paramMap && null != onceFanDes) {
            paramMap.put("CE1",onceFanDes.getE1());
            paramMap.put("CE2",onceFanDes.getE2());
            paramMap.put("CE3",onceFanDes.getE3());
            paramMap.put("CE4",onceFanDes.getE4());
            paramMap.put("CE5",onceFanDes.getE5());
            paramMap.put("CE6",onceFanDes.getE6());
            paramMap.put("CE7",onceFanDes.getE7());
            paramMap.put("CE8",onceFanDes.getE8());
            paramMap.put("CE9",onceFanDes.getE9());
            paramMap.put("CE10",onceFanDes.getE10());
            paramMap.put("CE11",onceFanDes.getE11());
            paramMap.put("CE15",onceFanDes.getE15());
            paramMap.put("CE18",onceFanDes.getE18());
            paramMap.put("CE19",onceFanDes.getE19());
            paramMap.put("CE20",onceFanDes.getE20());
            paramMap.put("CE21",onceFanDes.getE21());
            paramMap.put("CE42",onceFanDes.getE42());
            paramMap.put("CE52",onceFanDes.getE52());
            paramMap.put("CE63",onceFanDes.getE63());
        }
        return count + 19;
    }

    public int putOnceFanCalInit(int caseId) {
        paramMap.put("CE32",0.0);
        paramMap.put("CE25",0.0);
        return putOnceFanDesInit(caseId);
    }

    public int putOnceFanSummaryInit(int caseId) {
        int count = putOnceFanCalInit(caseId);
        OnceFanBaseCal onceFanBaseCal = onceFanBaseCalDao.getOnceFanBaseCal(caseId);
        if (null != onceFanBaseCal) {
            paramMap.put("CE25",onceFanBaseCal.getE25());
            paramMap.put("CE34",onceFanBaseCal.getE34());
            paramMap.put("CE37",onceFanBaseCal.getE37());
            paramMap.put("CE35",onceFanBaseCal.getE35());
            paramMap.put("CE38",onceFanBaseCal.getE38());
            paramMap.put("CE32",onceFanBaseCal.getE32());
        }
        return count + 6;
    }

    public int putBlowerDesInit(int caseId){
        int count = putOnceFanDesInit(caseId);
        BlowerDes blowerDes = blowerDesDao.getBlowerDes(caseId);
        if (null != paramMap && null != blowerDes){
            paramMap.put("SE1",blowerDes.getE1());
            paramMap.put("SE2",blowerDes.getE2());
            paramMap.put("SE3",blowerDes.getE3());
            paramMap.put("SE4",blowerDes.getE4());
            paramMap.put("SE5",blowerDes.getE5());
            paramMap.put("SE6",blowerDes.getE6());
            paramMap.put("SE7",blowerDes.getE7());
            paramMap.put("SE13",blowerDes.getE13());
            paramMap.put("SE14",blowerDes.getE14());
            paramMap.put("SE15",blowerDes.getE15());
            paramMap.put("SE16",blowerDes.getE16());
            paramMap.put("SE35",blowerDes.getE35());
            paramMap.put("SE45",blowerDes.getE45());
            paramMap.put("SE56",blowerDes.getE56());
        }
        return count + 14;
    }

    public int putBlowerCalInit(int caseId) {
        int count = putBlowerDesInit(caseId);
        paramMap.put("SE20",0.0);
        paramMap.put("SE25",0.0);
        return count + 2;
    }

    public int putBlwerSummaryInit(int caseId) {
        int count = putBlowerCalInit(caseId);
        BlowerBaseCal blowerBaseCal = blowerBaseCalDao.getBlowerBaseCal(caseId);
        if (null != blowerBaseCal) {
            paramMap.put("SE20",blowerBaseCal.getE20());
            paramMap.put("SE25",blowerBaseCal.getE25());
            paramMap.put("SE27",blowerBaseCal.getE27());
            paramMap.put("SE28",blowerBaseCal.getE28());
            paramMap.put("SE30",blowerBaseCal.getE30());
            paramMap.put("SE31",blowerBaseCal.getE31());
        }
        return count + 6;
    }

    public void putStepState(StepInfo stepInfo) {
        HashMap<Integer, Integer> stepState = (HashMap<Integer, Integer>) session.getAttribute("stepState");
        stepState.put(stepInfo.getStepId(), stepInfo.getState());
    }

    public HashMap<Integer, Integer> getStepState() {
        return (HashMap<Integer, Integer>) session.getAttribute("stepState");
    }

    public void addStepState(StepInfo stepInfo) {
        stepDao.addNewStep(stepInfo);
        putStepState(stepInfo);
    }

    public void finishStep(StepInfo stepInfo) {
        putStepState(stepInfo);
        stepInfo.setCaseId(getCaseId());
        stepDao.updateStepFinish(stepInfo);
    }

    public Boolean isFinishAll() {
        HashMap<Integer, Integer> stepState = getStepState();
        if (stepState.get(Constant.STEP_ID_1) < 1)
            return false;
        if (stepState.get(Constant.STEP_ID_2) > 0)
            return false;
        if (stepState.get(Constant.STEP_ID_3) > 0)
            return false;
        if (stepState.get(Constant.STEP_ID_4) > 0)
            return false;
        return true;
    }

    public Boolean isFinishBurn() {
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishAll() && (null != stepState.get(Constant.STEP_ID_6) && stepState.get(Constant.STEP_ID_6) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishPollution() {
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishBurn() && (null != stepState.get(Constant.STEP_ID_7) && stepState.get(Constant.STEP_ID_7) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishClean() {
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishPollution() && (null != stepState.get(Constant.STEP_ID_8) && stepState.get(Constant.STEP_ID_8) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishDewPoint() {
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishClean() && (null != stepState.get(Constant.STEP_ID_9) && stepState.get(Constant.STEP_ID_9) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishChimney() {
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishClean() && (null != stepState.get(Constant.STEP_ID_10) && stepState.get(Constant.STEP_ID_10) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishMillSelect() {
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishChimney() && (null != stepState.get(Constant.STEP_ID_11) && stepState.get(Constant.STEP_ID_11) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishSelectCalculate() {
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishMillSelect() && (null != stepState.get(Constant.STEP_ID_12) && stepState.get(Constant.STEP_ID_12) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishSystemHeat() {
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishSelectCalculate() && (null != stepState.get(Constant.STEP_ID_13) && stepState.get(Constant.STEP_ID_13) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishSodaParameter(){
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishSelectCalculate() && (null != stepState.get(Constant.STEP_ID_15) && stepState.get(Constant.STEP_ID_15) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishAisGasParameter(){
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishSelectCalculate() && (null != stepState.get(Constant.STEP_ID_16) && stepState.get(Constant.STEP_ID_16) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishEfficiency(){
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishSelectCalculate() && (null != stepState.get(Constant.STEP_ID_17) && stepState.get(Constant.STEP_ID_17) == Constant.STEP_OVER_STATE_1);
    }

    public boolean isFinishSummary(){
        HashMap<Integer, Integer> stepState = getStepState();
        return isFinishSelectCalculate() && (null != stepState.get(Constant.STEP_ID_18) && stepState.get(Constant.STEP_ID_18) == Constant.STEP_OVER_STATE_1);
    }

}
